import { reqSearchList } from '@/api/index'
// search模块的小仓库
let state = {
  searchList: {}
}
let mutations = {
  setSearchList: (state, searchList) => {
    state.searchList = searchList
  }
}
let actions = {
  getSearchList: async ({ commit }, params) => {
    const result = await reqSearchList(params)
    if (result.code == 200) {
      //提交mutation存储服务器数据
      commit('setSearchList', result.data)
    }
  }
}
//getters:仓库的计算属性
//项目中:vuex的getters,为了简化数据而生。
let getters = {
  //计算新的属性:state,当前小仓库的数据,防止没有返回 || []
  goodsList(state) {
    return state.searchList.goodsList || []
  },
  //品牌的数据
  trademarkList(state) {
    return state.searchList.trademarkList || []
  },
  //商品属性
  attrsList(state) {
    return state.searchList.attrsList || []
  },
  total(){
    return state.searchList.total || 0
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters
}
